class Node(object):
	def __init__(self, v, nx):
		self.v = v
		self.nx = nx
	def __str__(self):
		return str(self.v) + " -> " + ("*" if self.nx==None else str(self.nx))

def insert(head, p, x):
	"""
	Insert x after p in a list with the given head.
	If p==None, a new first node is created (using head).
	In order to create a guarded linked list, call with head=guard, p=None.
	Returns the (possibly new) head and the new pointer.
	This helper function is used everywhere to shorten .
	>>> print insert(Node(float("inf"), None), None, 42)[0]
	42 -> inf -> *
	>>> print insert(None, None, 42)[0]
	42 -> *
	>>> p = Node(2, None)
	>>> head = Node(1, p)
	>>> print insert(head, p, 3)[0]
	1 -> 2 -> 3 -> *
	"""
	if p == None:
		#first node
		head = p = Node(x, head)
	else:
		#next node
		p.nx = Node(x, p.nx)
		p = p.nx
	return (head, p)

def toLL(l, guardNode=None):
	"""
	Converts a list to a linked list. A guard node may be provided.
	This function is only here for writing shorter doctests.
	>>> print toLL([])
	None
	>>> print toLL([1])
	1 -> *
	>>> print toLL([1, 2, 3])
	1 -> 2 -> 3 -> *
	>>> print toLL([], Node(float("inf"), None))
	inf -> *
	>>> print toLL([1], Node(float("inf"), None))
	1 -> inf -> *
	>>> print toLL([1, 2, 3], Node(float("inf"), None))
	1 -> 2 -> 3 -> inf -> *
	"""
	(res, p) = (guardNode, None)
	for x in l:
		(res, p) = insert(res, p, x)
	return res

def getStandardGuard():
	"""
	Returns the standard linked list guard node (using inf).
	"""
	return Node(float("inf"), None)
	
def toStandardGuardedLL(l):
	"""
	Converts a list to a guarded linked list.
	This function is only here for writing shorter doctests.
	>>> print toStandardGuardedLL([])
	inf -> *
	>>> print toStandardGuardedLL([1])
	1 -> inf -> *
	>>> print toStandardGuardedLL([1, 2, 3])
	1 -> 2 -> 3 -> inf -> *
	"""
	return toLL(l, getStandardGuard())

def printEach(l):
	"""
	Prints each item of l (list or tuple).
	>>> printEach([1, 2])
	1
	2
	>>> printEach((1, 2))
	1
	2
	>>> printEach([])
	>>> printEach(())
	>>> printEach((getStandardGuard(), getStandardGuard()))
	inf -> *
	inf -> *
	"""
	for x in l:
		print x
